package org.stone.project.webIntegration.filter;

import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.stone.project.common.pojo.constant.WebFilterOrder;
import org.stone.project.common.utils.RequestIdUtil;
import org.stone.project.common.utils.ThreadTimeSnap;
import javax.servlet.*;
import java.io.IOException;

/**
 * 请求id记录过滤器
 */
@Order(WebFilterOrder.REQUEST_ID_ORDER)
@Component
public class RequestIdFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        //存储时间
        ThreadTimeSnap.getRecordTime();
        RequestIdUtil.getRequestId();
        filterChain.doFilter(servletRequest, servletResponse);
        ThreadTimeSnap.clear();
        RequestIdUtil.clear();
    }
}
